import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;

public class Bullet1 extends GameObject{// 보완중

//	public Image image;
//	public int x, y;
	public float vx, vy;
	public float distance;
	Player player;
	Player2 player2;
	Rectangle rect;

//	public boolean active;// 활성화 여부 -> 이 값이 false이면 관리 목록에서 제거
	private int enemy2x;
	private int enemy2y;

	public Bullet1(Image image, int x, int y, Player player,Player2 player2) {
		enemy2x = MainScreen.enemy2x;
		enemy2y = MainScreen.enemy2y;

		this.image = image;
		this.x = x;
		this.y = y;
		
		this.player = player;
		this.player2 = player2;

		if (0.4 > Math.random()) {
			abstandP1();
			VectorXP1();
			VectorYP1();
		} else {
			abstandP2();
			VectorXP2();
			VectorYP2();
		}
		rect = new Rectangle(image.getWidth(null), image.getHeight(null));
	}

	public void update() {
		x += vx;
		y += vy;
		if(x<(0-image.getWidth(null)) || y>(Constants.SCREEN_HEIGHT-image.getHeight(null)) || y<(0+image.getHeight(null))){
			active = false;
		}
	}

	public void render(Graphics g) {
		if (active) {// 활성 상태일 경우에만 화면에 출력
			g.drawImage(image, x, y, null);
		}
	}

	public Rectangle getArea() {
		rect.x = x;
		rect.y = y;
		return rect;
	}

	public void abstandP1() {
		this.distance = (float) Math.sqrt(// 피타고라스
				(player.x - enemy2x) * (player.x - enemy2x)
						+ (player.y - enemy2y) * (player.y - enemy2y));
	}

	public void VectorXP1() {
		this.vx = (float) (((player.x - enemy2x) / distance) * 5);
	}

	public void VectorYP1() {
		this.vy = (float) (((player.y - enemy2y) / distance) * 5);
	}

	public void abstandP2() {
		this.distance = (float) Math.sqrt(// 피타고라스
				(player2.x - enemy2x) * (player2.x - enemy2x)
						+ (player2.y - enemy2y) * (player2.y - enemy2y));
	}

	public void VectorXP2() {
		this.vx = (float) (((player2.x - enemy2x) / distance) * 5);
	}

	public void VectorYP2() {
		this.vy = (float) (((player2.y - enemy2y) / distance) * 5);
	}

}
